package com.zhaotianhao.service.impl;

import com.zhaotianhao.pojo.Brands;
import com.zhaotianhao.mapper.BrandsMapper;
import com.zhaotianhao.service.BrandsService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * (Brands)表服务实现类
 *
 * @author Z-7
 * @since 2022-03-01 11:17:34
 */
@DubboService
public class BrandsServiceImpl implements BrandsService {
    @Autowired
    private BrandsMapper brandsMapper;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public Brands queryById(Integer id) {
        return this.brandsMapper.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param brands 筛选条件
     * @param pageNum 起始页数
     * @param pageSize 分页偏移量
     * @return 查询结果
     */
    @Override
    public PageInfo<Brands> queryByPage(Brands brands,int pageNum,int pageSize) {
        PageHelper.startPage(pageNum,pageSize);
        return new PageInfo<>(this.brandsMapper.queryAll(brands));
    }

    /**
     * 新增数据
     *
     * @param brands 实例对象
     * @return 影响行数
     */
    @Override
    public int insert(Brands brands) {
        return this.brandsMapper.insert(brands);
    }

    /**
     * 修改数据
     *
     * @param brands 实例对象
     * @return 影响行数
     */
    @Override
    public int update(Brands brands) {
        return this.brandsMapper.update(brands);
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer id) {
        return this.brandsMapper.deleteById(id) > 0;
    }

    /**
     * 查询所有
     *
     * @return
     */
    @Override
    public List<Brands> queryAll() {
        return this.brandsMapper.queryAll(null);
    }
}
